using System.Windows.Threading;
using Mvvm;
using LayoutPlanning.Design;
using LayoutPlanning.Helpers;
using LayoutPlanning.Model;
using Microsoft.Practices.ServiceLocation;

namespace LayoutPlanning.ViewModel
{
    public class ViewModelLocator
    {
        public static Dispatcher Dispatcher;

        static ViewModelLocator()
        {
            ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

            if (ViewModelBase.IsInDesignMode)
            {
                SimpleIoc.Default.Register<ISaveLoadStationRelationService, SaveLoadStationRelationDesignService>();
                return;
            }
            else
            {
                SimpleIoc.Default.Register<ISaveLoadStationRelationService, SaveLoadStationRelationService>();
            }

            Dispatcher = Dispatcher.CurrentDispatcher;
            var stationRelationsViewModel =
                new StationRelationsViewModel(ServiceLocator.Current.GetInstance<ISaveLoadStationRelationService>());
            if (ViewModelBase.IsInDesignMode)
                stationRelationsViewModel.SelectedGraficalObject = new Station();
            SimpleIoc.Default.Register<StationRelationsViewModel>(
                () =>
                    stationRelationsViewModel);
            SimpleIoc.Default.Register<Layouts>(
                () =>
                    new Layouts());
            SimpleIoc.Default.Register<StationLoaderModel>(
                () =>
                    new StationLoaderModel());
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance",
            "CA1822:MarkMembersAsStatic",
            Justification = "This non-static member is needed for data binding purposes.")]
        public static StationRelationsViewModel Main => ServiceLocator.Current.GetInstance<StationRelationsViewModel>();

        public static Layouts Layouts => ServiceLocator.Current.GetInstance<Layouts>();

        public static StationLoaderModel Stations => ServiceLocator.Current.GetInstance<StationLoaderModel>();
    }
}